/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CapadeDatos;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import modelo.beanAutores;

/**
 *
 * @author principal
 */
public class DaoAutores {
public static  ArrayList datosautores(int Sistema){
        ArrayList lista = new ArrayList();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="call proc_autoressistema('"+Sistema+"') ";
            ResultSet rs =stm.executeQuery(sql);
            while (rs.next()){
                   beanAutores carrera  = new beanAutores();
                   carrera.setApellidoPaterno(rs.getString(1));
                   carrera.setApellidoMaterno(rs.getString(2));
                   carrera.setNombres(rs.getString(3));
                   carrera.setCelular(rs.getString(4));
                   carrera.setEmail(rs.getString(5));
                   carrera.setInformacion(rs.getString(6));
                   carrera.setEstado(rs.getString(7));
                   carrera.setOrganizacion(rs.getString(8));
                   carrera.setCargo(rs.getString(9));
                   lista.add(carrera);
            }
    }catch(Exception e){System.out.print(e);
   }return lista;
   }

public static  ArrayList vertodoslosautores(){
        ArrayList lista = new ArrayList();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="Select * from autores;"; // PROCEDIMIENTO ALMACENADO
            ResultSet rs =stm.executeQuery(sql);
            while (rs.next()){
                   beanAutores carrera  = new beanAutores();
                   carrera.setIdautores(rs.getInt(1));
                   carrera.setApellidoPaterno(rs.getString(2));
                   carrera.setApellidoMaterno(rs.getString(3));
                   carrera.setNombres(rs.getString(4));
                   carrera.setCelular(rs.getString(5));
                   carrera.setEmail(rs.getString(6));
                   carrera.setInformacion(rs.getString(7));
                   carrera.setEstado(rs.getString(8));
                   carrera.setOrganizacion(rs.getString(9));
                   carrera.setCargo(rs.getString(10));
                   lista.add(carrera);
        }
    }catch(Exception e){System.out.print(e);
   }return lista;
   }

public void insertarautores(String ApePaterno , String Apematerno,
        String nombres, String celular, String email, String Informacion,
        String cargo, String Organizacion, int Estado){
        Boolean verdad = false;
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="Call procregistrarautor('"
                    + ApePaterno + "', '"
                    + Apematerno + "', '"
                    + nombres +  "', '"
                    + celular+  "', '"
                    + email+  "', '"
                    + Informacion+ "', "
                    + Estado + ", '"
                    + Organizacion+  "', '"
                    + cargo + "');";         
            if(stm.executeQuery(sql).wasNull()){
               verdad = false;
               JOptionPane.showMessageDialog(null,"NO INGRESADO");
            }
            else {
                verdad = true;
                JOptionPane.showMessageDialog(null,"INGRESADO");
            }
    }catch(Exception e){System.out.print(e);
   }
   }

}
